package lu.med.praxiswahl.wahlumed.client.tarif;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableColumn;
import lu.med.praxiswahl.wahlumed.client.utilities.ColumnWidthControler;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;


/**
 * 
 * @author Lars Holger Roth
 */
public class TarifTable extends JTable
{

    /**
     * 
     */
    private static final long serialVersionUID = 3711423253017045941L;

    private ColumnWidthControler c;
	private boolean isColumnWidthChanged;
	private TableColumn resizedColumn;
	
	
    public TarifTable(TarifTableModel m)
    {
	super(m);
	this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	this.selectionModel = getSelectionModel();
	this.selectionModel
		.addListSelectionListener(new TarifTableSelectionListener(m));

	TableColumn column = null;

	c = new ColumnWidthControler(
		Main.COLUMNWIDTH_CONFIGURATION_FILE, "tariftbl", this);

	for (int i = 0; i < 4; i++)
	{
	    column = this.getColumnModel().getColumn(i);
	    column.setPreferredWidth(c.getColumnWidth(i));
	}
	
	this.getColumnModel().addColumnModelListener(new TableColumnWidthListener(this));
	this.getTableHeader().addMouseListener(new TableHeaderMouseListener(this, c));
	
    }
    
    public boolean getColumnWidthChanged() {
        return isColumnWidthChanged;
    }

    public void setColumnWidthChanged(boolean widthChanged, TableColumn resizedColumn) {
        isColumnWidthChanged = widthChanged;
        this.resizedColumn = resizedColumn;
    }

	public TableColumn getResizedColumn() {
		return resizedColumn;
	}
}
